<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>订单变更记录</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		var subFlag = true;
		$(document).ready(function() {
			
		});
		
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		
		function shows(n){
			$.ajax({
				 url: "${ctx}/sys/orderschangehistory/form", 
				 data:{"changeCode":n},
				 //async:false,
				 dataType:"json",
				 type:"post",
				 success: function(data){
				   if(data.resultCode == 1){
					   $("#changeTableBody").html(""); 
					   for(var i=0;i<data.detailList.length;i++){
						   var bean = data.detailList[i];
						   var tr = "<tr>"+
						   "<td>"+bean.goodsCnName+"</td>"+
						   "<td>"+bean.price+"</td>"+
						   "<td>"+bean.modifyPrice+"</td>"+
						   "<td>"+bean.num+"</td>"+
						   "<td>"+bean.modifyNum+"</td>"+
						   "</tr>";
						   $("#changeTableBody").append(tr);
					   }
					   var tr = "<tr>"+
					   "<td colspan='5'>原订单金额:"+data.orders.money+"</td>"+
					   "</tr>"+
					   "<tr>"+
					   "<td colspan='5'>变更后订单金额:"+data.orders.modifyMoney+"&nbsp;&nbsp;&nbsp;&nbsp;运费:";
					   if(data.orders.transportType == 1){
						   tr += data.orders.modifyFreight
					   }else{
						   tr += "到付";
					   }
					   "</tr>";
					   $("#changeTableBody").append(tr); 
					   $("#remarks").html(data.orders.remarks);
					   $("#importBox_goods").show();
				   }else{
					   alert(data.resultMessage);
					   subFlag = true;
				   }
				 },
				 error:function(){
					 alert("网络异常");
				 }
			})
		}
		
		function confirm_imbox(){
			if($("#forms").valid()){
				if(subFlag){
					//subFlag = false;
					//验证通过之后修改name属性方便后台接收为数组
					var alertName = $(".alertFlag");
					for(var i = 0 ; i < alertName.length; i++){
						alertName[i].name = alertName[i].name.substring(0,alertName[i].name.indexOf("_"));
					}
					/*
					$("#id").val(goodsId);
					$("#queryPartsCode2").val($("#queryPartsCode").val());
					$("#queryMaterielCode2").val($("#queryMaterielCode").val());
					$("#queryCnName2").val($("#queryCnName").val());
					$("#querySource2").val($("#querySource").val());
					$("#queryStoreCode2").val($("#queryStoreCode").val());
					*/
					$("#forms").submit();
				}else{
					loading('正在提交，请稍等...');
				}
			}
		}
		
		function close_imbox(){
			$("#importBox_goods").hide();
		}

	</script>
	
	<style>
		#importBox_goods{
			position:fixed;
			padding:0 15px;
			width:600px;
			background:#FFF;
			top:10%;
			left:25%;
			margin:0 auto;
			border:1px solid #CCC;
			box-shadow:3px 3px 10px 4px #DDD;
			z-index: 9999;
			
		}
		
		#importBox_goods .ib_bottom{
			margin-bottom:35px;
		}
       
	</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/sys/orderschange/">订单变更记录列表</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="orders" action="${ctx}/sys/orderschangehistory/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<ul class="ul-form">
			<li><label>变更单号：</label>
				<form:input path="changeCode" htmlEscape="false" maxlength="50" class="input-medium"/>
			</li>
			
		    <li><label>订单编号：</label>
				<form:input path="code" htmlEscape="false" maxlength="50" class="input-medium"/>
			</li>
			
			<li><label>变更时间：</label>
				<input name="starUpdateDate" type="text" readonly="readonly" placeholder="开始时间" class="input-medium Wdate " 
					value="<fmt:formatDate value="${order.createDate }" pattern="yyyy-MM-dd HH:mm:ss"/>"
			         onclick="WdatePicker({dateFmt:'yyyy-MM-dd 00:00:00',isShowClear:false});"/>
			     &nbsp;&nbsp;&nbsp;&nbsp;
			     <input name="endUpdateDate" type="text" readonly="readonly" placeholder="结束时间" class="input-medium Wdate " 
					value="<fmt:formatDate  value="${order.createDate }" pattern="yyyy-MM-dd HH:mm:ss"/>"
			     onclick="WdatePicker({dateFmt:'yyyy-MM-dd 23:59:59',isShowClear:false});"/> 
			</li> 
			<li>
			
			<li><label>下单门店：</label><form:select id="buyStoreCode" path="buyStoreCode" class="input-medium">
			<form:option value="" label="所有"/>
			<form:options items="${store}" htmlEscape="false" itemValue="code" itemLabel="cnName"/>
			</form:select>
			</li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/></li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>序号</th>
				<th>变更单号</th>
				<th>订单编号</th>
				<th>变更时间</th>
				<th>变更人</th>
				<th>下单门店</th>
				<th>原订单金额</th>
				<th>变更后订单金额</th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="orders" varStatus="status">
			<tr>
			    <td>${status.index+1}</td>
			    <td><a href="javascript:void(0);" onclick="shows('${orders.changeCode}')">${orders.changeCode}</a></td>
			    <td>${orders.code}</td>
				<td>
					<fmt:formatDate value="${orders.updateDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
				</td>
				<td>${orders.userName }</td>
				<td>${orders.buyStoreName}</td>
				<td>${orders.money}</td>
				<td>${orders.modifyMoney}</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
	
		<!-- 弹框 -->
	<div id="importBox_goods" class="hide">
			 <form action="${ctx}/sys/orderschange/save" method="post" id="forms">
			 	<div style="margin-top:20px;">
					<table id="changeTable" class="table table-striped table-bordered table-condensed">
						<thead>
							<tr>
								<th>商品名称</th>
								<th>原单价</th>
								<th>变更后单价</th>
								<th>原购买数量</th>
								<th>变更后购买数量</th>
							</tr>
						</thead>
						<tbody id="changeTableBody">
							
						</tbody>
					</table>
					变更说明:<span id="remarks" style="word-break: break-all;"></span>
				</div>
			  </form>
			<div class='ib_bottom'>
				<input id="btnCancel" class="btn" type="button" style='margin-left:10px;' value="关闭" onclick="close_imbox()"/>
			</div>	
	</div>
</body>
</html>